﻿using Hotel.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel.DAL
{
    public class DisDAL
    {
        public DisDAL(HotelConText hotelConText)
        {
            HotelConText = hotelConText;
        }

        public HotelConText HotelConText { get; }







        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="disCountModel"></param>
        /// <returns></returns>
        public int DisAdd(DisCountModel disCountModel)
        {

            HotelConText.disCounts.Add(disCountModel);
            return HotelConText.SaveChanges();
        }





        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="count"></param>
        /// <param name="page"></param>
        /// <param name="ShopName">门店名称</param>
        /// <param name="Titel">主题</param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>

        public List<DisCountModel> DisCountList( out int count, out int page,string? ShopName="-1", string? Titel ="",int index=1, int size = 3) 
        {
        
           var  list=HotelConText.disCounts.Where(x=>x.IsDeleted==false).AsQueryable();

            if (ShopName!="-1")
            {
                list = list.Where(x => x.ShopName == ShopName);
            }


            if (!string.IsNullOrEmpty(Titel))
            {
                list = list.Where(x => x.Titel.Contains(Titel));

            }
            count = list.Count();
            page = (int)Math.Ceiling(count * 1.0 / size);
            return list.OrderBy(x=>x.Id).Skip((index-1)* size).Take(size).ToList();
        }







        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DisCountDel(int id) 
        {
            var DisCountDels = HotelConText.disCounts.Find(id);
            DisCountDels.IsDeleted = true;
            return HotelConText.SaveChanges();
        }




        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DisCountModel DisCountAll(int id) 
        {
         return   HotelConText.disCounts.Find(id);


        }



        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="disCountModel"></param>
        /// <returns></returns>
        public  int DisCountUpd(DisCountModel disCountModel) 
        {
            var DisCountUpds = HotelConText.disCounts.Find(disCountModel.Id);
            if (DisCountUpds!=null)
            {
                DisCountUpds.ShopName = disCountModel.ShopName;
                DisCountUpds.Type = disCountModel.Type;
                DisCountUpds.Titel = disCountModel.Titel;
                DisCountUpds.Photo = disCountModel.Photo;
                DisCountUpds.FuWu = disCountModel.FuWu;
                DisCountUpds.BeginTime = disCountModel.BeginTime;
                DisCountUpds.EedTime = disCountModel.EedTime;
                DisCountUpds.Count = disCountModel.Count;
                DisCountUpds.Number = disCountModel.Number;
                DisCountUpds.ReleaseMoney = disCountModel.ReleaseMoney;
                DisCountUpds.ZheKou = disCountModel.ZheKou;

            }
            return HotelConText.SaveChanges();


        }


















    }
}
